//
//  ImgSimpleViewController.m
//  UITest
//
//  Created by wp w on 12-6-7.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ImgSimpleViewController.h"
#import "DLog.h"

@interface ImgSimpleViewController ()

@end

@implementation ImgSimpleViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    //创建imgview，并添加到view中
    UIImage *anImage = [UIImage imageNamed:@"apple.png"];
	UIImageView *myImageView = [[UIImageView alloc] initWithImage:anImage];
	
	[[self view] addSubview:myImageView];
	
    
    //将图片缩放，高度为宽度为原来的一半
    //重新设置imgview的frame
    //注意imgview的contentMode
	CGSize viewSize = myImageView.bounds.size;
	viewSize.width = viewSize.width * 0.5; //make our width 50% smaller
	viewSize.height = viewSize.height; //keep height the same
	
	CGRect newFrame = CGRectMake(0,0,viewSize.width, viewSize.height);
	[myImageView setFrame:newFrame];
	myImageView.contentMode = UIViewContentModeScaleAspectFit;//长宽按比例缩放
//    myImageView.contentMode = UIViewContentModeScaleToFill; //默认属性，长宽比例单独
	
	[myImageView release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
